namespace launch {
namespace cframework {

using System.Collections;
using UnityEngine.Networking;
    public static class UnityWebRequestManager
    {
        public const int timeout = 30;
        public static string AddFilePrefixIfNeed(string url)
        {
            if (!url.Contains("://"))
            {
                url = "file://" + url;
            }
            return url;
        }

    //public static void Request(string url, System.Action<UnityWebRequest> callback)
    //{
    //    if (!url.Contains("://"))
    //    {
    //        url = "file://" + url;
    //    }

    //    UnityWebRequest request = UnityWebRequest.Get(url);

    //    BehaviourEventMgr.instance.StartCoroutine(WaitRequestInternal(request, callback));
    //}


    //public static UnityWebRequest DownloadFile(string url, string localPath, System.Action<string, string, UnityWebRequest> callback)
    //{
    //        if (!url.Contains("://"))
    //        {
    //            url = "file://" + url;
    //        }

    //        var request = UnityWebRequest.Get(url);
    //        request.downloadHandler = new DownloadHandlerFile(localPath);

    //        BehaviourEventMgr.instance.StartCoroutine(WaitDownloadFileInternal(request, url, localPath, callback));

    //        return request;
    //}

    //    public static float GetDownloadProgress(UnityWebRequest request)
    //    {
    //        return request.downloadProgress;
    //    }

    //static IEnumerator WaitRequestInternal(UnityWebRequest request, System.Action<UnityWebRequest> callback)
    //{
    //    yield return request.SendWebRequest();

    //    callback?.Invoke(request);
    //}

    //static IEnumerator WaitDownloadFileInternal(UnityWebRequest request, string url, string localPath, System.Action<string, string, UnityWebRequest> callback)
    //{
    //    yield return request.SendWebRequest();

    //    callback?.Invoke(url, localPath, request);
    //}

    }

}

}